package com.example.question.tree.tree1;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2023-07-08
 * @Author Jonathan
 */
public class Code03_145 {

    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        dfs(res, root);
        return res;

    }

    private void dfs(List<Integer> res, TreeNode node) {
        if (node == null) {
            return;
        }
        dfs(res, node.left);
        dfs(res, node.right);
        res.add(node.val);
    }
}
